#include "board.hpp"
#include "chess_piece.hpp"
#include "minmax_player.hpp"
#include "alphabeta_player.hpp"
#include <fstream>
#include <iostream>
#define DEBUG
using namespace std;

int main() {
    Board board(Camp::RED);
    #ifndef DEBUG
    fstream is("board.txt", ios::in);
    fstream os("move.txt", ios::out);
    #endif
    #ifdef DEBUG
    istream &is = cin;
    ostream &os = cout;
    #endif
    try {
        string str;
        while(is >> str) {
            #ifdef DEBUG
            if(str == "0") break;
            #endif
            Camp camp = str == "Red" ? Camp::RED : Camp::BLACK;
            is >> str;
            auto piece = ChessPiece::parse(str, camp);
            int x, y;
            is >> x >> y;
            board.place(piece, Location(x, y));
        }
        // ai执红
        AlphabetaPlayer ai(Camp::RED, 5);
        auto decision = ai.decide(board);
        //decision.rotate();
        os << decision.from().x << ' ' << decision.from().y << ' ' << decision.to().x << ' ' << decision.to().y << endl;
        cout << decision.from().x << ' ' << decision.from().y << ' ' << decision.to().x << ' ' << decision.to().y << endl;
    } catch(const char *err) {
        cerr << err << endl;
    }
    return 0;
}